using AutoMapper;
using ERP.ERPSystem.HumanResources;
using ERP.ERPSystem.HumanResources.Dto;
using ERP.ERPSystem.OrderManagement.Dto;
using ERP.ERPSystem.ProductionSystem.Dto;
using ERP.ERPSystem.WarehouseManagement.Dto;
using ERP.Team.HumanResources;
using ERP.Team.OrderManagement;
using ERP.Team.ProductionSystem;
using ERP.Team.WarehouseManagement;

namespace ERP;

public class ERPApplicationAutoMapperProfile : Profile
{
    public ERPApplicationAutoMapperProfile()
    {
        /* You can configure your AutoMapper mapping configuration here.
         * Alternatively, you can split your mapping configurations
         * into multiple profile classes for a better organization. */
        
        CreateMap<JobGradeDto, JobGradeManagement>();
        CreateMap<JobGradeManagement, JobGradeDto>();

        CreateMap<ProductionWorkOrderMain, ProductionWorkOrderDto>();
        CreateMap<ProductionWorkOrderDto, ProductionWorkOrderMain>()
            .ForMember(dest => dest.CustomerCode, opt => opt.MapFrom(src => src.CustomerCode ?? ""))
            .ForMember(dest => dest.CustomerName, opt => opt.MapFrom(src => src.CustomerName ?? ""))
            .ForMember(dest => dest.Remark, opt => opt.MapFrom(src => src.Remark ?? ""));
            
        // 添加生产派单的映射配置
        CreateMap<ProductionDispatchMainDto, ProductionDispatchMain>();
        CreateMap<ProductionDispatchMain, ProductionDispatchMainDto>();
        
        // 添加生产退料的映射配置
        CreateMap<ProductionMaterialReturnDto, ProductionMaterialReturn>();
        CreateMap<ProductionMaterialReturn, ProductionMaterialReturnDto>();

        // 销售订单映射配置
        CreateMap<SalesOrderMainModel, SalesOrderDto>();
        CreateMap<SalesOrderDto, SalesOrderMainModel>();
        CreateMap<SalesOrderProductDetailModel, SalesOrderProductDetailDto>();
        CreateMap<SalesOrderProductDetailDto, SalesOrderProductDetailModel>();

        CreateMap<ProductInfoRelationModel, ProductInfoRelationDto>();
        CreateMap<ProductInfoRelationDto, ProductInfoRelationModel>();

        // 物料产品映射
        CreateMap<MaterialproductModel, MaterialProductDTO>();
        
        // 赋码管理物料产品映射
        CreateMap<MaterialproductModel, CodingMaterialProductDTO>()
            .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime));

        // 赋码管理映射
        CreateMap<CodingManagementDTO, CodingManagementModel>();
        CreateMap<CodingManagementModel, CodingManagementDTO>();
        
        // 添加班组设置的映射配置
        CreateMap<TeamSetDto, TeamSet>();
        CreateMap<TeamSet, TeamSetDto>();
    }
}
